import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter_xj_video/custom_drawer/drawer_item.dart';
import 'package:flutter_xj_video/custom_drawer/drawer_resource_controller.dart';
import 'package:flutter_xj_video/pages/film_list/view.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  Widget screenView;
  DrawerIndex drawerIndex;

  @override
  void initState() {
    drawerIndex = DrawerIndex.Mahuazy;
    screenView = FilmListPage(key: filmListKey);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
        top: false,
        bottom: false,
        child: DrawerResourceController(
          screenIndex: drawerIndex,
          drawerWidth: MediaQuery.of(context).size.width * 0.75,
          onDrawerCall: (DrawerItem drawerItem) {
            changeIndex(drawerItem);
          },
          screenView: screenView,
        ),
      ),
    );
  }

  void changeIndex(DrawerItem drawerItem) {
    setState(() {
      drawerIndex = drawerItem.index;
      screenView = FilmListPage(
        key: filmListKey,
      );
    });
    filmListKey.currentState.changeYuan(drawerItem);
  }
}
